package com.xitang.system.controller;

import com.xitang.common.dto.ResultVO;
import com.xitang.common.bean.BizUser;
import com.xitang.common.bean.SysUser;
import com.xitang.common.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "用户接口列表-系统")
@RestController
public class UserController extends BaseSystemController {
    @Autowired
    private IUserService userService;

    @ApiOperation(value = "获取系统用户信息", notes = "获取系统用户信息")
    @GetMapping("/sys_users")
    public ResultVO<List<SysUser>> listSysUsers() {
        List<SysUser> sysUsers = userService.listSysUsers();
        return ResultVO.success(sysUsers, sysUsers.size());
    }

    @ApiOperation(value = "获取业务用户信息", notes = "根据用户名获取业务用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "username", value = "用户名", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "vxUsername", value = "微信用户名", dataType = "String")
    })
    @GetMapping("/biz_users")
    public ResultVO<List<BizUser>> listBizUsers(@RequestParam(value = "username", required = false) String username,
                                                @RequestParam(value = "vxUsername", required = false) String vxUsername) {
        List<BizUser> bizUsers = userService.listBizUsers(username, vxUsername);
        return ResultVO.success(bizUsers, bizUsers.size());
    }

    @ApiOperation(value = "新增业务用户", notes = "新增业务用户")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = "bizUser", value = "用户信息", dataTypeClass = BizUser.class)
    })
    @PostMapping("/biz_user")
    public ResultVO<Integer> addBizUser(@RequestBody BizUser bizUser) {
        return ResultVO.success(userService.addBizUser(bizUser));
    }
}
